Linux开发

推荐列表 站点导航

当前位置:首页 > 服务器技术 > Linux开发 >

利用/proc/mounts检查已经被系统挂载的设备

来源:网络整理  作者:wy  发布时间:2020-12-24 01:39
1、介绍/proc/mounts 如何利用/proc/mounts知道已经挂载上的设备呢,我们先来看看/proc/mounts都有啥东西 解释一下,第一列...

1、介绍/proc/mounts

如何利用/proc/mounts知道已经挂载上的设备呢,我们先来看看/proc/mounts都有啥东西

利用/proc/mounts检查已经被系统挂载的设备

解释一下,第一列是设备路径,比如说/dev/sda1,第二列是挂载点(即设备挂载到的目录),第三列是以什么文件系统挂载。

 

2、编代码读取前3列

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int read_proc_mounts()

{

FILE IT之家fp = NULL;

int i = 0;

int nSscanfNum = 0;

char chDevicePath[255] = {0};

char chMountPath[255] = {0};

char chFsTypeName[255]= {0};

char chBuffer[1024] = {0};

fp = fopen("/proc/mounts","r");

if (NULL == fp)

{

printf("\n read  /proc/mounts  error! \n");

return -1;

}

while(1)

{

memset(chBuffer,0,sizeof(chBuffer));

if(NULL == fgets(chBuffer,sizeof(chBuffer),fp))

{

break;

}

memset(chDevicePath,0,sizeof(chDevicePath));

memset(chMountPath,0,sizeof(chMountPath));

memset(chFsTypeName,0,sizeof(chFsTypeName));

nSscanfNum = sscanf(chBuffer ,"%[^' '] %[^' '] %[^' ']",chDevicePath,chMountPath,chFsTypeName );

if(3 != nSscanfNum) 

{

continue;

}

printf("\nchDevicePath[%s],chMountPath[%s],chFstypeName[%s]\n",chDevicePath,chMountPath,chFsTypeName);

}

fclose(fp);

return 0;

}

int main()

{

read_proc_mounts();

return 0;

}

 

3、运行结果

-bash-3.2$ 

-bash-3.2$ gcc test_proc_mounts.c 

-bash-3.2$ 

-bash-3.2$ 

-bash-3.2$ ./a.out

chDevicePath[rootfs],chMountPath[/],chFstypeName[rootfs]

chDevicePath[/dev/root],chMountPath[/],chFstypeName[ext3]

chDevicePath[/dev],chMountPath[/dev],chFstypeName[tmpfs]

chDevicePath[/proc],chMountPath[/proc],chFstypeName[proc]

chDevicePath[/sys],chMountPath[/sys],chFstypeName[sysfs]

chDevicePath[/proc/bus/usb],chMountPath[/proc/bus/usb],chFstypeName[usbfs]

chDevicePath[devpts],chMountPath[/dev/pts],chFstypeName[devpts]

chDevicePath[/dev/sda6],chMountPath[/home],chFstypeName[ext3]

chDevicePath[/dev/sda5],chMountPath[/var],chFstypeName[ext3]

chDevicePath[/dev/sda1],chMountPath[/boot],chFstypeName[ext3]

chDevicePath[tmpfs],chMountPath[/dev/shm],chFstypeName[tmpfs]

chDevicePath[/dev/sdb1],chMountPath[/homesec],chFstypeName[ext4]

chDevicePath[/dev/sda6],chMountPath[/home_mount],chFstypeName[ext3]

chDevicePath[/dev/sdb1],chMountPath[/homesec_mount],chFstypeName[ext4]

chDevicePath[none],chMountPath[/proc/sys/fs/binfmt_misc],chFstypeName[binfmt_misc]

chDevicePath[sunrpc],chMountPath[/var/lib/nfs/rpc_pipefs],chFstypeName[rpc_pipefs]

chDevicePath[nfsd],chMountPath[/proc/fs/nfsd],chFstypeName[nfsd]

chDevicePath[/etc/auto.misc],chMountPath[/misc],chFstypeName[autofs]

chDevicePath[-hosts],chMountPath[/net],chFstypeName[autofs]

chDevicePath[/root],chMountPath[/root],chFstypeName[esn_cfs]

chDevicePath[/home],chMountPath[/home],chFstypeName[esn_cfs]

chDevicePath[/homesec],chMountPath[/homesec],chFstypeName[esn_cfs]

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/server/kaifa/8403.shtml

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

利用/proc/mounts检查已经被系统挂载的设备

2020-12-24 编辑:wy

1、介绍/proc/mounts

如何利用/proc/mounts知道已经挂载上的设备呢,我们先来看看/proc/mounts都有啥东西

利用/proc/mounts检查已经被系统挂载的设备

解释一下,第一列是设备路径,比如说/dev/sda1,第二列是挂载点(即设备挂载到的目录),第三列是以什么文件系统挂载。

 

2、编代码读取前3列

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int read_proc_mounts()

{

FILE IT之家fp = NULL;

int i = 0;

int nSscanfNum = 0;

char chDevicePath[255] = {0};

char chMountPath[255] = {0};

char chFsTypeName[255]= {0};

char chBuffer[1024] = {0};

fp = fopen("/proc/mounts","r");

if (NULL == fp)

{

printf("\n read  /proc/mounts  error! \n");

return -1;

}

while(1)

{

memset(chBuffer,0,sizeof(chBuffer));

if(NULL == fgets(chBuffer,sizeof(chBuffer),fp))

{

break;

}

memset(chDevicePath,0,sizeof(chDevicePath));

memset(chMountPath,0,sizeof(chMountPath));

memset(chFsTypeName,0,sizeof(chFsTypeName));

nSscanfNum = sscanf(chBuffer ,"%[^' '] %[^' '] %[^' ']",chDevicePath,chMountPath,chFsTypeName );

if(3 != nSscanfNum) 

{

continue;

}

printf("\nchDevicePath[%s],chMountPath[%s],chFstypeName[%s]\n",chDevicePath,chMountPath,chFsTypeName);

}

fclose(fp);

return 0;

}

int main()

{

read_proc_mounts();

return 0;

}

 

3、运行结果

-bash-3.2$ 

-bash-3.2$ gcc test_proc_mounts.c 

-bash-3.2$ 

-bash-3.2$ 

-bash-3.2$ ./a.out

chDevicePath[rootfs],chMountPath[/],chFstypeName[rootfs]

chDevicePath[/dev/root],chMountPath[/],chFstypeName[ext3]

chDevicePath[/dev],chMountPath[/dev],chFstypeName[tmpfs]

chDevicePath[/proc],chMountPath[/proc],chFstypeName[proc]

chDevicePath[/sys],chMountPath[/sys],chFstypeName[sysfs]

chDevicePath[/proc/bus/usb],chMountPath[/proc/bus/usb],chFstypeName[usbfs]

chDevicePath[devpts],chMountPath[/dev/pts],chFstypeName[devpts]

chDevicePath[/dev/sda6],chMountPath[/home],chFstypeName[ext3]

chDevicePath[/dev/sda5],chMountPath[/var],chFstypeName[ext3]

chDevicePath[/dev/sda1],chMountPath[/boot],chFstypeName[ext3]

chDevicePath[tmpfs],chMountPath[/dev/shm],chFstypeName[tmpfs]

chDevicePath[/dev/sdb1],chMountPath[/homesec],chFstypeName[ext4]

chDevicePath[/dev/sda6],chMountPath[/home_mount],chFstypeName[ext3]

chDevicePath[/dev/sdb1],chMountPath[/homesec_mount],chFstypeName[ext4]

chDevicePath[none],chMountPath[/proc/sys/fs/binfmt_misc],chFstypeName[binfmt_misc]

chDevicePath[sunrpc],chMountPath[/var/lib/nfs/rpc_pipefs],chFstypeName[rpc_pipefs]

chDevicePath[nfsd],chMountPath[/proc/fs/nfsd],chFstypeName[nfsd]

chDevicePath[/etc/auto.misc],chMountPath[/misc],chFstypeName[autofs]

chDevicePath[-hosts],chMountPath[/net],chFstypeName[autofs]

chDevicePath[/root],chMountPath[/root],chFstypeName[esn_cfs]

chDevicePath[/home],chMountPath[/home],chFstypeName[esn_cfs]

chDevicePath[/homesec],chMountPath[/homesec],chFstypeName[esn_cfs]

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/server/kaifa/8403.shtml

相关文章

风云图片

推荐阅读

返回Linux开发频道首页